/*
 * @Author: szx
 * @Date: 2022-03-21 15:31:56
 * @LastEditTime: 2022-03-21 15:35:45
 * @Description:
 * @FilePath: \leetcode\剑指offer\22\22.js
 */
/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */
/**
 * @param {ListNode} head
 * @param {number} k
 * @return {ListNode}
 */
var getKthFromEnd = function (head, k) {
    let last = head;
    while (k-- > 1) last = last.next;
    let cur = head;
    while (last.next != null) {
        cur = cur.next;
        last = last.next;
    }
    return cur;
};
